/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/

#ifndef MK_BUFFER_H
#define MK_BUFFER_H
#include "MkTime.h"

class MkApi CMkBuffer
{
public:
    CMkBuffer(const void* pBuf, Uint32 nLen);
    CMkBuffer(const CMkBuffer& Other);
    virtual ~CMkBuffer();
    Uint32 GetLength() const { return m_nLen; }
    const void* GetBuffer() const { return m_pBuf; }
protected:
    const void*         m_pBuf;
    Uint32              m_nLen;
};
typedef MkList<CMkBuffer> MkListBuffer;

class MkApi CMkStorageBuffer
{
public:
    CMkStorageBuffer(const CMkBuffer& MkBuffer);
    CMkStorageBuffer(const void* pBuf, Uint32 nLen);
    //CMkStorageBuffer(const CMkStorageBuffer& StorageBuffer);
    virtual ~CMkStorageBuffer();
    Uint32 GetLength() const { return m_nLen; }
    const void* GetBuffer() const { return m_pBuf; }
    const CMkTime& GetBuildTime() const { return m_BuildTime; }
protected:
private:
    void*       m_pBuf;
    Uint32      m_nLen;
    CMkTime     m_BuildTime;
};
typedef MkList<CMkStorageBuffer*> MkListStorageBuffer;

class MkApi CMkBufferList
{
public:
    CMkBufferList();
    ~CMkBufferList();

    Uint32 InsertHead(const CMkBufferList& BufList);
    Uint32 InsertHead(const CMkBuffer& Buffer);
    Uint32 InsertHead(const void* pBuffer, Uint32 nLen, Uint32 SplitSize = 0);
    Uint32 Append(const CMkBufferList& BufList);
    Uint32 Append(const CMkBuffer& pBuffer);
    Uint32 Append(const void* pBuffer, Uint32 nLen, Uint32 SplitSize = 0);
    const Uint32& GetTatolLen() const { return m_TotalLen; }
    Uint32 RemoveBegin(Uint32 RemoveCount);
    BOOL Empty() const { return m_ListBuffer.empty(); }
    Uint32 GetBufferCount() const { return m_ListBuffer.size(); }
    const MkListBuffer& GetBufferList() const { return m_ListBuffer; }
    void Clear() { m_ListBuffer.clear(); m_TotalLen = 0; }
    Uint32 GetBuffer(const Uint32& Offset, const Uint32& BufferLen, CMkBufferList& BufferList) const;
protected:
private:
    MkListBuffer                 m_ListBuffer;
    Uint32                       m_TotalLen;
};

class MkApi CMkStorageBufferList
{
public:
    CMkStorageBufferList();
    ~CMkStorageBufferList();

    //Uint32 InsertHead(const CMkBufferList& BufList);
    //Uint32 InsertHead(const CMkBuffer& Buffer);
    //Uint32 InsertHead(const void* pBuffer, Uint32 nLen, Uint32 SplitSize = 0);
    Uint32 Append(const CMkBufferList& BufList);
    Uint32 Append(const CMkBuffer& pBuffer);
    Uint32 Append(const void* pBuffer, Uint32 nLen, Uint32 SplitSize = 0);
    Uint32 GetTatolLen() const { return m_TotalLen; }
    Uint32 RemoveBegin(Uint32 RemoveCount);
    Uint32 GetBeginBuildTime(CMkTime& BeginTime) const;
    BOOL Empty() const { return m_ListBuffer.empty(); }
    Uint32 GetBufferCount() const { return m_ListBuffer.size(); }
    const MkListStorageBuffer& GetStorageBufferList() const { return m_ListBuffer; }
    Uint32 GetBufferList(CMkBufferList& BufferList) const;
    void Clear(); //mast clear by user
protected:
private:
    MkListStorageBuffer                 m_ListBuffer;
    Uint32                              m_TotalLen;
};


#endif

